import JSEncrypt from "jsencrypt";
import {Utils} from "@/utils/utils";
/**
 * 非对称加密
 */
export class RsaUtils {

    private static publicKey = '';
    private static encrypt = new JSEncrypt();

    /**
     * 设置公钥
     * @param key
     */
    static setPublicKey(key: string) {
        this.publicKey = key;
    }

    /**
     * 加密数据
     * @param word
     * @constructor
     */
    static RsaEncrypt(word: string): string | false {
        if (!Utils.enableEncrypt) return word;
        this.encrypt.setPublicKey(this.publicKey); //设置公钥
        return this.encrypt.encrypt(word);
    }
}